<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <f:view>
        <h:head>
            <title>Facelet Title</title>
        </h:head>
        <h:body>
            <ui:composition template="/Admin/AdminMasterLayout.xhtml">
                <ui:define name="event">
                    <f:event type="preRenderView" listener="#{users.checkLogin}"/>
                </ui:define>
                <ui:define name="Title">
                    Location
                </ui:define>

                <ui:define name="content">
                    <h:form id="f1" >
                        <p:tabView id="tabView">
                            <p:tab id="tab1" title="Thành phố">
                                <p:commandButton value="Add" onclick="dlg1.show();"></p:commandButton>

                                <p:dataTable value="#{Cities.listCities()}" var="c" emptyMessage="Chưa có dữ liệu"
                                             paginator="true" rows="10"  
                                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                             rowsPerPageTemplate="5,10,15">
                                    <f:facet name="header">
                                        <h:outputText value="Danh sách địa điểm"/>
                                    </f:facet>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Id"/>
                                        </f:facet>
                                        <h:outputText value="#{c.cityid}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Name"/>
                                        </f:facet>
                                        <h:outputText value="#{c.cityname}"/>
                                    </p:column>

                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Edit"/>
                                        </f:facet>
                                        <p:commandButton action="#{Cities.deleteCity(c)}"  value="Delete"/>
                                        <p:commandButton value="Edit"/>
                                    </p:column>
                                </p:dataTable>

                                <p:commandButton value="Refresh Table" update="@(.ui-datatable)"/>

                                <p:dialog header="Add new city" width="360" widgetVar="dlg1" showEffect="fade" hideEffect="slide">
                                    <h:panelGrid columns="2">

                                        <h:outputText value="City: "/><p:inputText value="#{Cities.newCity.cityname}"/>

                                        <p:commandButton value="Update"  
                                                         actionListener="#{Cities.addCity()}">
                                        </p:commandButton>
                                        <p:commandButton value="Cancel"  update="@(.ui-datatable)" />
                                    </h:panelGrid>
                                </p:dialog><br/>
                            </p:tab>
                            <p:tab id="tab2" title="Địa chỉ">
                                <p:commandButton value="Add" onclick="dlg.show();"></p:commandButton>

                                <p:dataTable styleClass="table1" id="table1" value="#{locations.listLocation()}" var="location" emptyMessage="Chưa có dữ liệu"
                                             paginator="true" rows="10"  
                                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                             rowsPerPageTemplate="5,10,15">
                                    <f:facet name="header">
                                        <h:outputText value="Danh sách địa điểm"/>
                                    </f:facet>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Id"/>
                                        </f:facet>
                                        <h:outputText value="#{location.locationid}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Address"/>
                                        </f:facet>
                                        <h:outputText value="#{location.address}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="City"/>
                                        </f:facet>
                                        <h:outputText value="#{location.city}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Country"/>
                                        </f:facet>
                                        <h:outputText value="#{location.country}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Description"/>
                                        </f:facet>
                                        <h:outputText value="#{location.description}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">
                                            <h:outputText value="Edit"/>
                                        </f:facet>
                                        <p:commandButton action="#{locations.deleteLocation(location)}"  value="Delete"/>
                                        <p:commandButton value="Edit"/>
                                    </p:column>
                                </p:dataTable>

                                <p:commandButton value="Refresh Table" update="@(.ui-datatable)"
                                                 />
                                <p:dialog header="Add new location" width="360" widgetVar="dlg" showEffect="fade" hideEffect="slide">
                                    <h:panelGrid columns="2">
                                        <h:outputText value="Address: "/><p:inputTextarea maxHeight="50" id="txtAddress" value="#{locations.newLocation.address}"/>
                                        <h:outputText value="City: "/><p:inputText id="txtCity" value="#{locations.newLocation.city}"/>
                                        <h:outputText value="Country: "/><p:inputText id="txtCountry" value="#{locations.newLocation.country}"/>
                                        <h:outputText value="Description: "/><p:inputText id="txtDescrition" value="#{locations.newLocation.description}"/>
                                        <p:commandButton value="Update"  
                                                         actionListener="#{locations.addLocation()}">
                                        </p:commandButton>
                                        <p:commandButton value="Cancel"  update="@(.ui-datatable)" />
                                    </h:panelGrid>
                                </p:dialog><br/>
                            </p:tab>
                        </p:tabView>
                    </h:form>
                </ui:define>
            </ui:composition>
        </h:body>
    </f:view>
</html>

